﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;

namespace DAL
{
    public class CR_VIPUserDAL
    {
        public string GetBossIDByUserName(string UserName)
        {
            string BossID = string.Empty;

            using(MySqlConnection conn = SqlHelper.Settings.GetBrandMySqlConnection(false))
            {
                try
                {
                    string SqlStr = "SELECT BossID FROM CR_VIPUser WHERE UserName = @UserName";
                    MySqlCommand cmd = new MySqlCommand(SqlStr, conn);
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add("@UserName", MySqlDbType.VarChar, 20).Value = UserName;
                    if(conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }
                    using (MySqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        if(sdr["BossID"] != DBNull.Value)
                        {
                            BossID = sdr["BossID"].ToString();
                        }
                        return BossID;
                    }
                }
                catch (Exception ex)
                {
                    ActCommon.Log.WriteLog(this.GetType().FullName + "GetBossIDByUserName(date:" + System.DateTime.Now + "):error:" + ex.Message + ";StackTrace" + ex.StackTrace, "arcyun");
                    return "-1000";
                }
                finally
                {
                    conn.Close();
                }     
            }
        }
    }
}
